package net.ys.dao;

import net.ys.bean.AprApollo;
import net.ys.dao.mapper.AprApolloMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: NMY
 * @Date: 2022/3/16
 * @Time: 8:04
 */
@Repository
public class ApiDao {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public long queryApolloCount() {
        String sql = "SELECT COUNT(*) FROM apr_apollo";
        return jdbcTemplate.queryForObject(sql, Long.class);
    }

    public List<AprApollo> listApollo(int page, int pageSize) {
        String sql = "SELECT id, project_name, app_name, namespace, config_key, config_value, tapd_type, tapd_id, create_time, update_time, env_test_commit, env_pre_commit, env_prod_commit FROM apr_apollo LIMIT ?,?";
        List<AprApollo> query = jdbcTemplate.query(sql, new AprApolloMapper(), (page - 1) * pageSize, pageSize);
        return query;
    }
}
